import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import myindex from '@/components/myindex'
import myreg from '@/components/myreg'
import mylogin from '@/components/mylogin'
import userinfo from '@/components/userinfo'
import permission from '@/components/permission'
import mycate from '@/components/mycate'
import showcate from '@/components/showcate'
import addcourse from '@/components/addcourse'
import courselist from '@/components/courselist'
import courseinfo from '@/components/courseinfo'

Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/myindex',
          name:'myindex',
          component:myindex
        },{
          path:'/myreg',
          name:'myreg',
          component:myreg
        },{
          path:'/mylogin',
          name:'mylogin',
          component:mylogin
        },{
          path:'/userinfo',
          name:'userinfo',
          component:userinfo,
          // 拦截器
          beforeEnter: (to, from, next) => {
            if(localStorage.getItem('username')){
              console.log('登录了')
              next();
            }else{
              alert('未登录，请去登录')
              next('/mylogin');  
            }
          }
        },{
          path:'/permission',
          name:'permission',
          component:permission
        },{
          path:'/mycate',
          name:'mycate',
          component:mycate
        },{
          path:'/showcate',
          name:'showcate',
          component:showcate
        },{
          path:'/addcourse',
          name:'addcourse',
          component:addcourse
        },{
          path:'/courselist',
          name:'courselist',
          component:courselist
        },{
          path:'/courseinfo',
          name:'courseinfo',
          component:courseinfo
        },
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})